<?php
/**
 * Created by PhpStorm.
 * User: Frings
 * Date: 2017-10-22
 * Time: 12:44
 */

use yii\helpers\Url;

$web = Url::base();
$scriptUrl = \Yii::$app->request->scriptUrl;

?>


<div class="panel panel-default">
    <div class="panel-body">
        <div class="form-inline">
        </div>
    </div>
</div>

<div class="panel">
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed">
                <thead class="nowrap">
                <tr>
                    <th>代理商名称</th>
                    <th>商家名称</th>
                    <th>广告标题</th>
                    <th>平台费率</th>
                    <th>平台费</th>
                    <th>支付方式</th>
                    <th>创建时间(元)</th>
                </tr>
                </thead>
                <tbody>
                <?php
                foreach ($items as $item) {
                    ?>
                    <tr>
                        <td><?= $item['agent_name'] ?></td>
                        <td><?= $item['merchant_name'] ?></td>
                        <td><?= $item['title']?></td>
                        <td><?= $item['agent_rake_fee_rate'] * 100 . '%' ?></td>
                        <td><?= $item['agent_rake_fee'] ?></td>
                        <td><?= $item['pay_mode'] == 1 ? '微信支付' : '余额支付' ?></td>
                        <td><?= $item['create_datetime'] ?></td>
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
        <?= \app\widgets\LinkPagerExt::widget(['pagination' => $pagination]) ?>
    </div>
</div>


<script type="application/javascript">
    (function () {

        $('#btnAddOk').click(function () {
            var data = {};
            data.id = $("#agent_id").val();
            data.agent_name = $('#agent_name').val();
            data.agent_province_id = $('#agent_province').val();
            data.agent_city_id = $('#agent_city').val();
            data.agent_county_id = $('#agent_county').val();
            data.is_enabled = $("#is_enable").val();

            requestJson('agent-save-handler', data, true, function (responseData) {
                if (responseData.status == 0) {
                    window.location.reload();
                }
            })


        });

        $('#detailModal').on('show.bs.modal', function (e) {
            $("#detail_content").html('正在加载数据....');
            var id = e.relatedTarget.attributes['data-id'].value;
            var data = {};
            data.id = id;
            requestHtml('agent-detail-partial', data, true, function (responseHtml) {
                $("#detail_content").html(responseHtml);
            });
        });

        $('.btn-delete-item').click(function () {
            var result = confirm('是否确认删除此广告?');
            if (result == true) {
                var id = $(this).attr('data-id');
                requestJson('ad-delete-handler', {'id': id}, true, function (responseData) {
                    if (responseData.status == 0) {
                        window.location.reload();
                    }
                });
            }
        });

    })(jQuery);

    //设置模态窗:当用户点击模态框外部时不会关闭、当初始化时不显示模态框。
    $(function () {
        $('#addModal').modal({
            backdrop: 'static', show: false
        });

        $('#detailModal').modal({
            backdrop: 'static', show: false
        });

    });
</script>

